The IDLffVideoWrite object creates a video file with an optional soundtrack. The process for creating a video file is:
None.
This class has the following methods:
IDLffVideoWrite::AddVideoStream
IDLffVideoWrite::AddAudioStream
In addition, this class inherits the methods of its superclasses (if any).
This example creates an MP4 video of a rotating surface graphic, and includes an audio track.
PRO surfaceVideo_ex
file = FILEPATH('surface.mp4', /TMP)
width = 500
height = 500
frames = 180
fps = 30
speed = 2
samplerate = 22050L
; Create object and initialize video/audio streams
oVid = IDLffVideoWrite(file)
vidStream = oVid.AddVideoStream(width, height, fps)
audStream = oVid.AddAudioStream(samplerate)
; Generate some audio
audio = FINDGEN(samplerate * frames / fps)
audio = SIN(audio * 2 * !PI / samplerate) * samplerate / 22
audio = SIN(audio * 2 * !PI / samplerate * 1000)
audio = FIX(30000 * audio)
time = oVid.Put(audStream, audio)
; Generate video frames
surf = SURFACE(/TEST, DIMENSIONS=[width,height])
FOR i = 0, frames-1 DO BEGIN
time = oVid.Put(vidStream, surf.CopyWindow())
surf.Rotate, speed
ENDFOR
surf.Close
; Close the file
oVid.Cleanup
END
Initializes the object and creates the video file.
Result = IDLffVideoWrite( Filename [, FORMAT=string])
When this method is called indirectly, as in the previous syntax, the return value is an object reference to the newly-created object.
When called directly within a subclass Init method, the return value is 1 if initialization was successful, or zero otherwise.
A string that specifies the full path and name of the video file (container format) to create. If the file already exists, it will be overwritten. You can specify the file type by including a filename extension or by setting the optional FORMAT keyword. The IDL-supported file type extensions are:
Extension | File Type |
---|---|
.avi | Audio Video Interleave |
.mp4 | MPEG-4 |
Note: For a list of all available file types, call IDLffVideoWrite::GetFormats.
Set this keyword to a string that specifies the file type (container format) to create. You can also specify the file type by including a filename extension when setting Filename.The IDL-supported strings are:
String | File Type |
---|---|
'avi' | Audio Video Interleave |
'mp4' | MPEG-4 |
Note: For a list of all available file types, call IDLffVideoWrite::GetFormats.
This function method adds a new video stream to the file.
Result = Obj.[IDLffVideoWrite::]AddVideoStream( Width, Height, Fps [, BIT_RATE=Value] [, CODEC=string] [, PRESET=string])
Returns the index of the new stream.
The frame width in pixels.
The frame height in pixels.
The frames per second at which the video file is meant to be played back.
Note: Very low frame rates (<5 FPS) can be problematic for many codecs and players. Rather than setting FPS this low, it is recommended that you set some multiple of the desired frame rate and output each frame several times. Because of the way most codecs encode video, the increase in file size is usually negligible.
The target output data rate of the video encoder, in bits per second. Larger values produce higher quality video, but larger files. Actual results may be slightly larger or smaller.
Set this keyword to the codec to use for encoding the data. For a video stream in a MP4-format file, the default value is 'MP4'.
Note: For a list of all available codecs, call IDLffVideoWrite::GetCodecs.
Set this keyword to a string that selects one of the built-in encoding presets for the H.264 video codec. Because the version of FFmpeg included with IDL does not support H.264, this argument is useful only if you have replaced the FFmpeg version. See Replacing the FFmpeg Version.
This argument is equivalent to the -vpre
argument to the command-line FFmpeg utility. Valid values are:
ultrafast |
slower |
superfast |
veryslow |
veryfast |
max |
faster |
placebo |
fast |
lossless_ultrafast |
normal |
lossless_fast |
default |
lossless_medium |
medium |
lossless_slow |
hq |
lossless_slower |
slow |
lossless_max |
This function method adds a new audio stream to the file.
Nearly all video formats require audio (if any) to be interlaced in the file with video frames, but IDLffVideoWrite does not require the user to output audio and video data this way. To permit this behavior, video and audio data is kept in memory until it can be interlaced and written out to a file.
The key to minimizing memory use is to keep all of the streams in the video synchronized--alternately write out a frame of video and some fraction of a second of audio. If you must do all of one and then the other, outputting audio first requires less memory.
Result = Obj.[IDLffVideoWrite::]AddAudioStream(Rate [, BIT_RATE=value][, CHANNELS=value] [, CODEC=string])
Returns the index of the new stream.
The audio sample rate in Hertz. Not all values are guaranteed to work, depending upon the codec used. Suggested values are 44100 (CD quality), 22050, and 11025.
The target output data rate of the audio encoder, in bits per second. Larger values produce higher quality audio, but larger files. Actual results may be slightly larger or smaller.
Set this keyword to the number of audio channels in the stream. For example, 1 = mono, 2 = stereo.
Set this keyword to the codec to use for encoding the data. For an audio stream in a MP4-format file, the default value is 'AAC'.
Note: If you add only audio streams to an IDLffVideoWrite object, you can only use the MPEG-4 container format (file type).
Note: For a list of all available codecs, call IDLffVideoWrite::GetCodecs.
This function method returns the list of codecs you may use to encode a video or audio stream.
Result = Obj.[IDLffVideoWrite::]GetCodecs([/AUDIO] [, /LONG_NAMES] [, /VIDEO])
Returns the available codecs as an array of strings. These strings are the same names accepted by the CODEC keyword of the AddVideoStream and AddAudioStream methods (unless the LONG_NAMES keyword is set).
None
Set this keyword to return only available audio codecs.
Set this keyword to return longer, more descriptive names.
Set this keyword to return only available video codecs.
This function method returns the video file types (container formats) you can create.
Result = Obj.[IDLffVideoWrite::]GetFormats(/LONG_NAMES)
Returns a list of available file formats as an array of strings. These strings are the same names accepted by the FORMAT keyword of the Init method (unless the LONG_NAMES keyword is set).
None
Set this keyword to return longer, more descriptive format names.
This function method writes data into the stream identified by Index.
Result = Obj.[IDLffVideoWrite::]Put(Index, Data)
A floating-point value giving the point in the timeline (in seconds) that was assigned to the given data.
The data stream index returned by the AddVideoStream or AddAudioStream methods.
The data to be written to the stream.
For video, the data must be represented as bytes in the format [3,w,h] with w and h matching the stream's original width and height.
For audio, the data must be represented as 16-bit integers and arranged in an array of the format [n, s] to write s samples (as many as desired) into n channels (n must match the number of channels in the stream). If you are writing one channel, [1,s] and [s] are functionally equivalent, and both formats are accepted.
This function method returns an array of structures describing each of the streams contained in the video file.
Result = Obj.[IDLffVideoWrite::]GetStreams( )
Returns an array of structures describing each of the streams contained in the video file. These structures are of the following format:
{
PID, ; Program ID - The internal identifier for the stream
type, ; 0=unknown, 1=video, 2=audio, 3=data
rate, ; Rate in Hertz. For example, 25 FPS for video, or 44100 Hz for audio
width, ; Video only. Width in pixels
height, ; Video only. Height in pixels
channels, ; Audio only. Number of audio channels
codec, ; String identifying the codec used
length, ; Stream length in seconds
}
This method embeds a metadata string in the video file.
Note: You can not call the SetMetadata method after you call the Put method.
Obj.[IDLffVideoWrite::]SetMetadata, Key, Value
A case-insensitive string value. Keys unsupported by the file format are ignored.
The following table lists the metadata keys recognized by the IDL-supported video file formats. Other formats may have their own list of recognized metadata keys.
Key |
---|
album |
artist |
comment |
copyright |
genre |
title |
A string value.
None
oVid.SetMetadata, 'title', 'Yeti photographed by wildlife cam'
This method finalizes and closes the file, and then destroys the object. The file is not playable until you destroy the object.
Obj.[IDLffVideoWrite::]Cleanup
8.1 |
Introduced |
8.2 | Added PRESET keyword to ::AddVideoStream method. |